Skip to content

fix: reject server-initiated streams in send_headers - #1352

Open
feiiiiii5 wants to merge 1 commit into
python-hyper:masterfrom
feiiiiii5:feiiiiii5/issue-contract-h2-server-headers
Open

feiiiiii5 wants to merge 1 commit into
python-hyper:masterfrom
feiiiiii5:feiiiiii5/issue-contract-h2-server-headers

Conversation

@feiiiiii5

Copy link
Copy Markdown

H2Connection.send_headers documented that "It is a protocol error for a server to open a stream by sending headers", but the implementation created the stream regardless of connection side: a fresh server connection could send HEADERS on an even-numbered stream and open it. A server-initiated stream is only legal after PUSH_PROMISE, which push_stream() handles.

A guard in send_headers now raises ProtocolError when the server sends HEADERS on a stream not already in self.streams, before any state or output is mutated. Client behavior, upgrade stream 1, and PUSH_PROMISE-reserved streams are unchanged.

Verification: base source fails the new server test (DID NOT RAISE); with the fix tests/test_basic_logic.py is 392 passed and the full suite is 1687 passed. ruff check on source and mypy --strict-bytes pass; three lint errors in the test file are pre-existing on base. A server upgrade sanity check also passes.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant